﻿#light

module PubSim.Coffee

open System
open Microsoft.FSharp.Control

/// Coffee type definition ... used to set status of whether coffee is on the shelf
/// or not.
type Coffee(initValue) =
    let mutable coffee = initValue
    let lockObj = new Object()

    member c.AddCoffeeToCupboard() =
        coffee <- true
        ignore()
    member c.FetchCoffeeFromCupboard() =
        lock lockObj (fun() -> 
            if coffee = true then
                coffee <- false
                true
            else
                false
        )
    member c.IsCoffeeInCupboard() =
        coffee
